/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.FUNCTION.PASSBOOK;

import BUS.CustomerBUS;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Mr.Sam
 */
public class TablePassBook extends AbstractTableModel{
    CustomerBUS customer_bus=new CustomerBUS();
        DefaultTableModel model;
        Vector Header=new Vector();
        JTable table;
        public void SetTable(JTable table)
        {
            this.table=table;
        }
        public JTable Gettable()
        {
            return this.table;
        }
        public void SetHeader()
        {
            Header.add("Mã Sổ");
            Header.add("Tên Khách Hàng");
            Header.add("CMND");
            Header.add("Tên Loại Kỳ Hạn");
            Header.add("Lãi Suất");
            Header.add("Số Tiền Gửi");
            Header.add("Ngày Mở Sổ");
            model=new DefaultTableModel(Header,0);
            table.setModel(model);
        }
        public void RemoveHeader()
        {
            Header.removeAllElements();
        }
        public void RemoveData()
        {
            RemoveHeader();
            while(table.getRowCount()>0)
            {
                ((DefaultTableModel)table.getModel()).removeRow(0);
            }
        }
        public void SetData(String sql) throws Exception
        {
            SetHeader();
            ResultSet rss=customer_bus.ExcuteQuery("{call dbo.ExcuteQuery(?)}",sql);
            if(rss!=null)
            {
                while(rss.next())
                {
                    Vector RowData=new Vector();
                    RowData.add(rss.getString(1));
                    RowData.add(rss.getString(2));
                    RowData.add(rss.getString(3));
                    RowData.add(rss.getString(4));
                    RowData.add(rss.getFloat(5));
                    RowData.add(rss.getFloat(6));
                    RowData.add(rss.getDate(7));
                    model.addRow(RowData);
                }
            }
        }

    @Override
    public int getRowCount() {
        return table.getRowCount();
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int getColumnCount() {
        return table.getColumnCount();
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return table.getValueAt(rowIndex, columnIndex);
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }   
}
